package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class POSCalTax extends AbstractData {
	private long id = -1;
	private double taxValue;
	private POSTax tax;
	private String taxString;

	public POSCalTax() {
	}

	public POSCalTax(long id) {
		this.id = id;
	}
	
	public double getTaxValue() {
		return taxValue;
	}

	public void setTaxValue(double taxValue) {
		this.taxValue = taxValue;
	}
	public POSTax getTax() {
		if (tax == null && !(taxString == null || taxString.isEmpty())) {
			POSTax m = new POSTax(Long.parseLong(taxString));
			m.LoadData();
			tax = m;
		}
		return tax;
	}

	public void setTax(POSTax tax) {
		this.taxString = String.format("%d", tax.getId());
		this.tax = tax;
	}
	
	public void setTaxString(String taxString){
		this.taxString = taxString;
	}
	
	public String getTaxString(){
		return this.taxString;
	}

	@Override
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}

	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.POSCalTax);
		else
			item = new Entity(this.key);
		item.setProperty("tax", this.taxString);
		item.setProperty("taxValue", this.taxValue);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.taxString = (String) entity.getProperty("tax");
		this.taxValue = (Double) entity.getProperty("taxValue");
		
		this.key = entity.getKey();
	}

	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.POSCalTax, this.id);
			setEntity(entity);
		}
	}

}
